//
//  TMSystemsMessController.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/29.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMSystemsMessController.h"
#import "TMPushCell.h"
#import "TMMyComplaintController.h"
#import "TMPushModel.h"
#import "TMPaySuccessController.h"
#import "TMUserViewModel.h"
@interface TMSystemsMessController ()
@property (nonatomic, strong) NSMutableArray *listArray;
@property (nonatomic, strong) NSMutableArray *pushArray;
@property (nonatomic, strong) WZNoResultView *noResultView;
@property (nonatomic, strong) TMUserViewModel *viewModel;
@end

@implementation TMSystemsMessController
-(NSMutableArray *)listArray{
    if (!_listArray) {
        _listArray = [NSMutableArray array];
    }
    return _listArray;
}
-(NSMutableArray *)pushArray{
    if (!_pushArray) {
        _pushArray = [NSMutableArray array];
    }
    return _pushArray;
}
- (WZNoResultView *)noResultView{
    if (!_noResultView) {
        _noResultView = [[[NSBundle mainBundle] loadNibNamed:@"WZNoResultView" owner:nil options:nil]firstObject];
        _noResultView.frame = CGRectMake(0, 0, kWindowW, kWindowH);
        _noResultView.isSearchVC = YES;
        [self.tableView addSubview:_noResultView];
    }
    return _noResultView;
}
- (void)noResultViewShowORNot{
    if (!self.listArray.count) {
        self.noResultView.hidden = NO;
    }else{
        self.noResultView.hidden = YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.isPush? @"平台通知": @"系统消息";
    [self.tableView registerNib:[UINib nibWithNibName:@"TMPushCell" bundle:nil] forCellReuseIdentifier:@"TMPushCell"];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.estimatedRowHeight = 58;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.viewModel = [[TMUserViewModel alloc]init];
//    if (self.isPush == YES) {
        [self.viewModel getSysMessageSuccess:^(id responseObject) {
            self.listArray = responseObject;
            [self noResultViewShowORNot];
            [self.tableView reloadData];
        } failed:^(NSString *error) {
            [self noResultViewShowORNot];
            [self.tableView reloadData];
        }];
   // }
//    if (self.isPush == YES) {
//        [self.listArray addObject:self.model];
////        [[NSUserDefaults standardUserDefaults] setObject:self.listArray forKey:@"arrays"];
////        [[NSUserDefaults standardUserDefaults] synchronize];
//    }else{
//        //self.listArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"arrays"];
//    }
    
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TMPushCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TMPushCell" forIndexPath:indexPath];
    cell.model = self.listArray[indexPath.row];
    return cell;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 58;
//
//}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isPush == YES) {
//        TMPaySuccessController *vc = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil] instantiateViewControllerWithIdentifier:@"TMPaySuccessController"];
//        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end
